using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Text;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebTools.UI.WebControls
{
	#region Xml Doc
	/// <summary>
	/// A control that displays a client scripted rollover image and responds to mouse clicks on the image.
	/// </summary>
	/// <remarks>
	/// <para>
	/// The RolloverImageButton control provides a standard rollover image useful for navigation buttons, etc. The RolloverImageButton 
	/// control handles the output of client script required to allow the rollover to function and preload the over images. 
	/// </para>
	/// <para>
	/// Using the RolloverImageButton control does not require any client script knowledge or code but does require browsers that support 
	/// client side scripting.
	/// </para>
	/// </remarks>
	/// <example>
	/// <para>
	/// The following example demonstrates the default use of the RolloverImageButton control.
	/// </para>
	/// <code>
	/// <![CDATA[
	/// <webtools:RolloverImageButton ID="rolloverButton" runat="server" 
	/// 				ImageUrl="images/tab_off.gif" 
	/// 				MouseOutImageUrl="images/tab_off.gif" 
	/// 				MouseOverImageUrl="images/tab_over.gif" 
	/// 				ToolTip="My Tab" OnClientClick="ShowTabPanel();" />
	/// ]]>
	/// </code>
	/// <para>
	/// The following example demonstrates the use of the TargetImageControlID and CaptionControlID. This example will render 
	/// the MouseOverImageUrl value to the "targetImage" control and disables the MouseOut event. It will also display the 
	/// caption text in the "captionLabel" control.
	/// </para>
	/// <code>
	/// <![CDATA[
	/// <asp:image id="targetImage" runat="server" ImageUrl="blank_image.gif" /><br/>
	/// <asp:label id="captionLabel" runat="server" /><br/>
	/// <webtools:RolloverImageButton ID="rolloverButton" runat="server" 
	///					TargetImageControlID="targetImage"
	///					CaptionControlID="captionLabel"
	///					Caption="My Image"
	/// 				ImageUrl="images/thumbnail.gif" 
	/// 				MouseOverImageUrl="images/full_size_image.gif" 
	///					EnableMouseOut="false"
	/// 				ToolTip="My Tab" OnClientClick="ShowTabPanel();" />
	/// ]]>
	/// </code>
	/// </example>
	#endregion
	[System.Drawing.ToolboxBitmap("WebTools.UI.WebControls.RolloverImageButton.bmp")]
	[ToolboxData(@"<{0}:RolloverImageButton runat=""server""></{0}:RolloverImageButton>")]
	[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class RolloverImageButton : ImageButton, IRollover
	{
		/// <summary>
		/// Initializes a new instance of the WebTools.UI.WebControls.RolloverImageButton.
		/// </summary>
		public RolloverImageButton()
		{
		}

		#region Event Handlers
		/// <summary>
		/// Raises the System.Web.UI.Control.PreRender event.
		/// </summary>
		/// <param name="e">An System.EventArgs object that contains the event data.</param>
		protected override void OnPreRender(EventArgs e)
		{
			this.OnPreRender(e, this.IsEnabled);
		}

		/// <summary>
		/// Raises the System.Web.UI.Control.PreRender event.
		/// </summary>
		/// <param name="e">An System.EventArgs object that contains the event data.</param>
		/// <param name="registerScript">A value indicating whether or not the client scripts should be registered with the page.</param>
		internal void OnPreRender(EventArgs e, bool registerScript)
		{
			base.OnPreRender(e);

			RolloverManager.RegisterClientScript(this, registerScript);
		}
		#endregion

		#region Render Methods
		/// <summary>
		/// Adds HTML attributes and styles that need to be rendered to the specified 
		/// System.Web.UI.HtmlTextWriterTag. This method is used primarily by control developers.
		/// </summary>
		/// <param name="writer">A System.Web.UI.HtmlTextWriter that represents the output stream to render 
		/// HTML content on the client.</param>
		protected override void AddAttributesToRender(HtmlTextWriter writer)
		{
			base.AddAttributesToRender(writer);

			RolloverManager.AddAttributesToRender(writer, this);
		}
		#endregion

		#region Properties

		/// <summary>
		/// Gets or sets the path to an image to display for the WebTools.UI.WebControls.RolloverImageButton when the mouse hovers over the control.
		/// </summary>
		/// <value>The path to the image to display for the WebTools.UI.WebControls.RolloverImageButton 
		/// when the mouse hovers over the control. The default value is an empty string ("").</value>
		[Bindable(true)]
		[Category("Appearance")]
		[DefaultValue("")]
		[Editor("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
		[UrlProperty]
		[Description("The image to display when the mouse hovers over the control.")]
		public virtual string MouseOverImageUrl
		{
			get
			{
				string text = (string)this.ViewState["MouseOverImageUrl"];
				if (text != null)
				{
					return text;
				}
				return string.Empty;
			}
			set
			{
				this.ViewState["MouseOverImageUrl"] = value;
			}
		}

		/// <summary>
		/// Gets or sets the path to an image to display for the WebTools.UI.WebControls.RolloverImageButton when the mouse leaves the control.
		/// </summary>
		/// <value>The path to the image to display for the WebTools.UI.WebControls.RolloverImageButton 
		/// when the mouse leaves the control. The default value is an empty string ("").</value>
		[Bindable(true)]
		[Category("Appearance")]
		[DefaultValue("")]
		[Editor("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
		[UrlProperty]
		[Description("The image to display when the mouse leaves the control.")]
		public virtual string MouseOutImageUrl
		{
			get
			{
				string text = (string)this.ViewState["MouseOutImageUrl"];
				if (text != null)
				{
					return text;
				}
				return string.Empty;
			}
			set
			{
				this.ViewState["MouseOutImageUrl"] = value;
			}
		}

		/// <summary>
		/// Gets or sets the ID of the Image control that will display the mouseover image state instead of the current image control.
		/// </summary>
		/// <value>The ID property value of the control that will display the mouse over image when the mouse is moved over the current image.</value>
		/// <remarks>
		/// <para>
		/// This property will allow you to specify an image control that will display the mouse over image whenever the mouse is moved 
		/// over the current image. This is useful for image galleries where you may have thumbnail images that when rolled over change 
		/// a large image to the side or above the thumbnails.
		/// </para>
		/// </remarks>
		[Themeable(false)]
		[TypeConverter(typeof(AssociatedControlConverter))]
		[Category("Accessibility")]
		[IDReferenceProperty]
		[DefaultValue("")]
		[Description("The ID of the Image control that will display the mouseover image state instead of the current image control.")]
		public virtual string TargetImageControlID
		{
			get
			{
				string text = (string)this.ViewState["TargetImageControlID"];
				if (text != null)
				{
					return text;
				}
				return string.Empty;
			}
			set
			{
				this.ViewState["TargetImageControlID"] = value;
			}
		}

		/// <summary>
		/// Gets the identifier of the image that is rendered for the rollovers. This ID will be used when the 
		/// client script methods are called for image replacement.
		/// </summary>
		/// <value>The unique id assigned by the .NET framework.</value>
		[Browsable(false)]
		[Description("ImageClientID")]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public virtual string ImageClientID
		{
			get
			{
				return this.ClientID;
			}
		}

		/// <summary>
		/// Gets or sets the ID of the server control that will display the Caption.
		/// </summary>
		/// <value>A server control that will display the caption text for the image.</value>
		/// <remarks>
		/// <para>
		/// Any HTML element that has an innerText property can be used it only needs a runat=server attribute defined.
		/// </para>
		/// </remarks>
		[Themeable(false)]
		[TypeConverter(typeof(AssociatedControlConverter))]
		[Category("Accessibility")]
		[IDReferenceProperty]
		[DefaultValue("")]
		[Description("The ID of the server control that will display the Caption. Define runat=server for non ASP.NET server controls.")]
		public virtual string CaptionControlID
		{
			get
			{
				string text = (string)this.ViewState["CaptionControlID"];
				if (text != null)
				{
					return text;
				}
				return string.Empty;
			}
			set
			{
				this.ViewState["CaptionControlID"] = value;
			}
		}

		/// <summary>
		/// Gets or sets a value to indicate whether or not the mouse over event is to be used.
		/// </summary>
		/// <value>True if the mouse over event should be used; otherwise false. The default is true.</value>
		/// <remarks>
		/// The mouse over and mouse out events can be disabled if you only desire one aspect of the rollover.
		/// </remarks>
		[Bindable(true)]
		[Description("A value to indicate whether or not the mouse over event is to be used.")]
		[DefaultValue(true)]
		[Category("Behaviour")]
		public bool EnableMouseOver
		{
			get
			{
				object obj = this.ViewState["EnableMouseOver"];
				if (obj != null)
				{
					return (bool)obj;
				}
				return true;
			}
			set
			{
				this.ViewState["EnableMouseOver"] = value;
			}
		}

		/// <summary>
		/// Gets or sets a value to indicate whether or not the mouse out event is to be used.
		/// </summary>
		/// <value>True if the mouse out event should be used; otherwise false. The default is true.</value>
		/// <remarks>
		/// The mouse over and mouse out events can be disabled if you only desire one aspect of the rollover.
		/// </remarks>
		[Bindable(true)]
		[Description("A value to indicate whether or not the mouse out event is to be used.")]
		[DefaultValue(true)]
		[Category("Behaviour")]
		public bool EnableMouseOut
		{
			get
			{
				object obj = this.ViewState["EnableMouseOut"];
				if (obj != null)
				{
					return (bool)obj;
				}
				return true;
			}
			set
			{
				this.ViewState["EnableMouseOut"] = value;
			}
		}

		/// <summary>
		/// Gets or sets text to display with the image.
		/// </summary>
		/// <value>The String value of a title or caption to display with the image.</value>
		/// <remarks>
		/// When the Caption property is used the CaptionControlID should be set to an HTML control that the client 
		/// script will used to insert this caption text.
		/// </remarks>
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		[Bindable(true)]
		[Description("The text to display with the image.")]
		[DefaultValue("")]
		[Category("Appearance")]
		[Localizable(true)]
		public string Caption
		{
			get
			{
				string text = (string)this.ViewState["Caption"];
				if (text != null)
				{
					return text;
				}
				return string.Empty;
			}
			set
			{
				this.ViewState["Caption"] = value;
			}
		}
		#endregion
	}
}
